<?php

namespace App\Admin\Controllers\exam;

use App\Common\statement\CommonStatement;
use App\Models\exams\UserExam;
use Carbon\Carbon;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class UserExamController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '试题';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new UserExam());

        $grid->model()->groupBy('user_id','exam_id')->orderByDesc('id');

        $grid->disableCreateButton();
        $grid->disableExport();
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableView();
        });
        $grid->filter(function ($filter) {
            $filter->disableIdFilter();
            $filter->column(1 / 2, function ($filter) {
                $filter->like('exam.title', __('Title'));
            });

            $filter->column(1 / 2, function ($filter) {
                $filter->equal('user.name', __('姓名'));
            });
        });

        $grid->column('id', __('ID'));
        $grid->column('exam.title', __('Title'));
        $grid->column('user.name', __('姓名'));
        $grid->column('score', __('分值'));
        $grid->column('continue_time', __('持续时间(分钟)'));
        $grid->column('start_time', __('Start Time'));
        $grid->column('end_time', __('End Time'));
        $grid->column('updated_at', __('Updated at'));
        return $grid;
    }

}
